package com.kit.data.kitopeso.activity;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.viewbinding.ViewBinding;

import com.kit.data.kitopeso.KitoApp;
import com.kit.data.kitopeso.base.BaseActivity;
import com.kit.data.kitopeso.databinding.KitoPrivacyActivityBinding;
import com.kit.data.kitopeso.tools.ViewUtils;

public class KitoPrivacyActivity extends BaseActivity<KitoPrivacyActivityBinding> {


    String url;

    @Override
    protected KitoPrivacyActivityBinding initViewBinding(LayoutInflater inflater) {
        return KitoPrivacyActivityBinding.inflate(inflater);
    }

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void initView() {

        url = getIntent().getStringExtra("url");

        WebSettings webSettings = binding.webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        binding.webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (binding!=null&& getActivity() != null && !isFinishing() && !isDestroyed() && !TextUtils.isEmpty(url)) {
                    binding.webview.loadUrl(url);
                }
                return true;
            }

        });
        binding.webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                if (binding!=null && getActivity() != null && !isFinishing() && !isDestroyed()) {
                    if (!TextUtils.isEmpty(title)) {
                        binding.tvTitle.setText(title);
                    }
                }
            }
        });
        binding.tvBk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewUtils.viewScale(v);
                finish();
            }
        });

        url = "https://www.baidu.com";

//        url = "https://sites.google.com/tambwe.info/kitopesoservice";


        if (KitoApp.getInstance().getAppInfo() != null && !TextUtils.isEmpty(KitoApp.getInstance().getAppInfo().getPrivacyUrl())) {
            url = KitoApp.getInstance().getAppInfo().getPrivacyUrl();
        }
        if (!url.isEmpty()) {
            binding.webview.loadUrl(url);
        }

    }

    @Override
    protected void initData() {

    }
}
